package com.wangzh.network.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class ReceiveDemo2 {
    public static void main(String[] args) throws IOException {

        DatagramSocket ds = new DatagramSocket(10086);

        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        while (true) {
            ds.receive(dp);
            byte[] data = dp.getData();
            InetAddress address = dp.getAddress();

            System.out.print("该数据是从:"+address.getHostName()+"端口："+dp.getPort());
            System.out.println("接收到数据:"+new String(data,0,dp.getLength()));

        }


    }
}
